{layout name="public/layout" /}
{include file='yxnavbar'}


<div class="main">
    {include file='education/record_nav'}
    {if $action == 10}
    <div class="panel panel-info">
        <div class="panel-heading">当前数量： {$page_total}</div>
        <div class="panel-body">
            <form id = "myform" action="./index.php" method="get" class="form-horizontal" role="form">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="web" />
                <input type="hidden" name="r" value="education.flag.course" />
                <div class="form-group">
                    <label class="col-xs-1 col-sm-1 col-md-1 control-label">商家</label>
                    <div class="col-xs-11 col-sm-9 col-md-9">
                        <div class="btn-group">
                            {loop $shangjia $row}
                            <a href="{php echo createWebUrlPlugin('education.flag.course',array('themeid'=>$themeid,'shangjiaid'=>$row['id']));}" class="btn {if $shangjiaid == $row['id']}btn-primary{else}btn-default{/if}">
                                {$row['name']}
                                <span style="color: #ff0000">{$row['total']}</span>
                            </a>
                            {/loop}
                        </div>

                    </div>
                    {if count($themelist)>1 }
                    <div class="col-xs-12 col-sm-2 col-md-2">
                        <select onchange="submitForm();" class="form-control" name="themeid">
                            {loop $themelist $row}
                            <option value="{$row['id']}" {if $themeid == $row['id'] }selected="selected"{/if}>{$row['id']} - {php echo mb_substr($row['title'],0,8,'utf-8');}</option>
                            {/loop}
                        </select>
                    </div>
                    {else}
                    <input type="hidden" name="themeid" value="{$themeid}" />
                    {/if}
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">创建时间</label>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        {php echo view_form_field_daterange('createtime', array('start'=>date('Y-m-d H:i:s',$starttime),'end'=>date('Y-m-d H:i:s',$endtime)), true);}
                    </div>

                </div>
                <div class="form-group clearfix">
                    <label class="col-xs-12 col-sm-3 col-md-1 control-label">关键字</label>
                    <div class="col-sm-3 col-xs-3 col-md-3">
                        <input class="form-control" name="search_data" placeholder="输入报名手机号或微信昵称" type="text" value="{$_P['search_data']}">
                    </div>
                    <div class="col-sm-3 col-lg-3 col-md-3 col-xs-6">
                        <button class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                        <input type="hidden" name="__token__" value="{$Request.token}"/>
                    </div>
                    <div class="col-sm-2 col-lg-2 col-md-2 col-xs-2" style="display: flex;flex-direction: row;">
                        {if $shangjiaid}
                        <input type="hidden" name="shangjiaid" value="{$shangjiaid}">
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出记录EXCEL">
                        {else}
                        {if $total<=5000}
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出记录EXCEL">
                        {else}
                        <input class="btn btn-default" type="submit" name="export_submit" onclick="jump()" id="export_submit" value="导出记录EXCEL(1-5000条)">
                        {/if}
                        {/if}
                        <input class="btn btn-default" type="button" onclick="openAlert1()"  value="导出商家订单课程礼品优惠券记录">
                    </div>
                </div>
            </form>
        </div>
    </div>
    {/if}

    <div class="tab-content">
        <div class="panel panel-default">
            <div class="panel-body table-responsive">
                <table class="table table-hover">
                    <thead class="navbar-inner">
                    <tr>
                        <th style="width: 50px">序号</th>
                        <th style="width: 70px">昵称</th>
                        <th style="width: 100px">姓名/电话</th>
<!--                        增加表单信息-->
                        {if !empty($config['datetime'])}
                        <th style="width: 100px;">{$config['datetime']}</th>
                        {/if}
                        {if !empty($config['address'])}
                        <th style="width: 100px">{$config['address']}</th>
                        {/if}
                        {if !empty($config['formtwo'])}
                        <th style="width: 100px">{$config['formtwo']}</th>
                        {/if}
                        {if !empty($config['addinfo'])}
                        <th style="width: 100px">{$config['addinfo']}</th>
                        {/if}
                        {if !empty($config['shops']) &&  $config['shopstype']!=8}
                        <th style="width: 100px">{$config['shops']}</th>
                        {/if}
                        <!--                        增加表单信息-->
                        <th style="width: 100px">课程名称</th>

                        <th style="width: 100px">选择校区</th>
                        <th style="width: 100px">提供商家</th>
                        <th style="width: 100px">课程状态</th>
                        <th style="width: 100px">课程核销人</th>
                        <th style="width: 100px">订单支付金额</th>
                        <th style="width: 100px">归属员工</th>
                        <th style="width: 80px">创建时间</th>
                        <th style="width: 100px;text-align: right">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {loop $list $index $item}
                    <tr>
                        <td>{$item['id']}</td>
                        <td>
                            <img src="{php echo tomedia($item['avatar']);}" style="width: 40px;height: 40px;padding: 1px;">
                            <br>
                            {$item['nickname']}
                        </td>
                        <td>{$item['username']}<br/>{$item['mobile']}</td>
<!--                        增加表单信息-->
                        {if !empty($config['datetime'])}
                        <td  style="font-size: 10px;max-width: 100px;">
                            {$item['datetime']}
                        </td>
                        {/if}
                        {if !empty($config['address'])}
                        <td  style="font-size: 10px;min-width: 60px; max-width: 100px;">
                            {$item['raddress']}
                        </td>
                        {/if}
                        {if !empty($config['formtwo'])}
                        <td  style="font-size: 10px;min-width: 60px; max-width: 100px;">
                            {$item['formtwo']}
                        </td>
                        {/if}
                        {if !empty($config['addinfo'])}
                        <td  style="font-size: 10px;max-width: 100px;">
                            {$item['addinfo']}
                        </td>
                        {/if}
                        {if !empty($config['shops']) &&  $config['shopstype']!=8}
                        <td  style="font-size: 10px;max-width: 100px;">
                            {if $config['shopstype']==8}
                            <div style="max-width: 100px;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;">
                                {loop $item['option'] $index1 $row1}
                                {if $index1==0}
                                <span class="label label-success" style="max-width: 100px;white-space: normal;text-align: left;margin-bottom: 4px;">
									{elseif $index1==1}
										<span class="label label-warning" style="max-width: 100px;white-space: normal;text-align: left;margin-bottom: 4px;">
									{else}
											{if $index1>2}
												<span class="label label-danger all_course" style="max-width: 100px;white-space: normal;display: none;text-align: left;margin-bottom: 4px;">
											{else}
												<span class="label label-danger" style="max-width: 100px;white-space: normal;text-align: left;margin-bottom: 4px;">
											{/if}

									{/if}
									{$row1}</span>
								{/loop}
											{if count($item['option'])>3}
											<a href="javascript:void(0);" class="showUserCourse" style="color: dodgerblue;font-size: 12px;">查看全部</a>
											{/if}
                            </div>
                            {else}
                            {php echo str_replace('|','<br>',$item['option']);}
                            {/if}
                        </td>
                        {/if}
<!--                        增加表单信息-->
                        <td>{$item['name']}</td>
                        <td>{$item['address']}</td>
                        <td>{$item['shangjianame']}</td>
                        <td>
                            {if !$item['status']}
                            <span class="label label-danger">待核销</span>
                            {else}
                            <span class="label label-success">已核销</span>
                            {/if}
                        </td>
                        <td>{if $item['status']}员工-{$item['verify_name']}{/if}</td>
                        <td>{$item['fee']}元</td>
                        <td>{$item['workenname']}</td>

                        <td>
                            {$item['created_at']}
                        </td>
                        <td style="text-align: right">
                            {if !$item['status']}
                            <a class="btn btn-danger btn-sm" href="javascript:void(0);" onclick="openAlert(this)" data-id="{$item['id']}" data-shangjiaid="{$item['shangjiaid']}" data-uid="{$item['uid']}"
                               title="修改课程" data-toggle="tooltip" data-placement="top"><i class="fa 	fa fa-book">修改课程</i></a>
                            {/if}
                            <a class="btn btn-primary btn-sm" href="{php echo createWebUrl('record', array('op'=>'display','themeid'=>$themeid,'keyword'=>$item['order_mobile']));}"  title="查看订单" data-toggle="tooltip" data-placement="top"><i class="fa fa-money">查看订单</i></a>
                        </td>
                    </tr>
                    {/loop}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!--修改课程-->
<style>
    .div_flex{
        display: flex !important;
    }
    .div_none{
        display: none; !important;
    }
    .shadow-box{
        width: 100%;
        height: 100%;
        position: fixed;
        top: 0;
        left: 0;
        background: rgba(0,0,0,0.5);
    }
    #alert_form {
        position: absolute;
        top: 10%;
        left: 30%;
        background: #fff;
        min-height: 40%;
        min-width: 40%;
    }
    #alert_form1{
        position: absolute;
        top: 20%;
        left: 30%;
        background: #fff;
        min-height: 30%;
        min-width: 30%;
    }
    .shadow-box .panel-body{
        max-height: 88%;
        overflow-y: auto;
    }
    .table td span{display:inline-block;margin-top:4px;}
    .table td input{margin-bottom:0;}
    .form-horizontal .form-group{
        margin-left: -15px;
        margin-right: -15px;
    }
    .form-group{
        margin-bottom: 30px;
        height: auto;
    }
    .demo{
        display:-webkit-box;
        display:-webkit-flex;
        display:-ms-flexbox;
        display:flex;
        -webkit-box-pack:justify;
        -webkit-justify-content:space-between;
        -ms-flex-pack:justify;
        justify-content:space-between;
    }

    .demo div{
        width:50%;
    }
    .ad_mq{
        display: none;
    }
</style>
<div class="shadow-box div_none" id="shadow-box" >
    <div class="panel panel-default" role="tabpanel" id="alert_form">
        <div class="panel-heading demo" >
            <div>用户课程修改</div>
            <div style="text-align: right;"><input name="button" onclick="closeAlert()" id="btnConfirm2" type="button" value="关闭" class="btn btn-danger col-lg-2" style="float: right"></div>
        </div>
        <div class="panel-body" style="z-index:188;display: flex;flex-direction: column;" >
            <form action="" method="post" class="form-horizontal" role="form" name="form" id="form" style="padding:10px;">
                <input type="hidden" id="course_id" name="course_id" value=""/>
                <input type="hidden" id="uid" name="uid" value=""/>
                <input type="hidden" name="themeid" value="{$themeid}"/>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">选择商家</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <select class="form-control" name="shangjia" id="shangjia" onchange="changeSj();">
                                {loop $shangjia $row}
                                <option value="{$row['id']}" >{$row['name']}</option>
                                {/loop}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">选择课程</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <select class="form-control" name="course" id="course" onchange="changeKc();">
                                <option value="" >请选择课程</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">选择地址</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <select class="form-control" name="adress" id="adress">
                                <option value="" >请选择地址</option>
                            </select>
                        </div>
                    </div>
                </div>


                <div class="form-group" id="sub_upload" >
                    <div class="col-sm-12">
                        <input name="submit" onclick="addOrEditItem()" id="btnConfirm" type="button" value="提交" class="btn btn-primary col-lg-2" style="float: left;width: 200px;">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<!-- 弹出选择商家-->
<div class="shadow-box div_none" id="shadow-box1">
    <div class="panel panel-default" role="tabpanel" id="alert_form1">
        <div class="panel-heading demo" >
            <div>选择导出记录商家</div>
            <div style="text-align: right;"><input name="button" onclick="closeAlert1()" id="btnConfirm21" type="button" value="关闭" class="btn btn-danger col-lg-2" style="float: right;width: 60px;"></div>
        </div>
        <div class="panel-body" style="z-index:188;display: flex;flex-direction: column;" >
            <form action="" method="post" class="form-horizontal" role="form" name="form" id="form2" style="padding:10px;">
                <input type="hidden" name="c" value="site" />
                <input type="hidden" name="a" value="entry" />
                <input type="hidden" name="m" value="{$_P['m']}" />
                <input type="hidden" name="do" value="web" />
                <input type="hidden" name="r" value="education.flag.course" />
                <input type="hidden" name="shangjiaid" id="form_shangjiaid" value="" />
                <div class="form-group">
                    <label class="col-sm-2 col-xs-12 control-label">选择商家</label>
                    <div class="col-sm-8 col-xs-12">
                        <div class="input-group">
                            <select class="form-control" name="shangjia" id="shangjia11" onchange="changeSj11();">
                                {loop $shangjia $row}
                                <option value="{$row['id']}" >{$row['name']}</option>
                                {/loop}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="form-group" id="sub_upload2" style="display: none;" >
                    <div class="col-md-8 col-sm-12">
                        <input name="export_submit2" onclick="jump()"  type="submit" value="导出商家订单课程礼品优惠券记录" class="btn btn-primary col-lg-2" style="float: left;width: 300px;">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

{$pager}
<script type="text/javascript">
    function jump(){
        layer.msg('正在准备下载');
    }
    <!--	课程-->
    $(".showUserCourse").click(function () {
        if ($(this).hasClass("hideUserCourse")){
            $(this).parent().find(".all_course").hide();
            $(this).html('查看全部');
            $(this).removeClass("hideUserCourse");
        }else{
            $(".all_course").hide();
            $(this).parent().find(".all_course").show();
            $(this).html('隐藏全部');
            $(this).addClass("hideUserCourse");
        }
    });
<!--    选择商家-->
    function closeAlert1() {
        $("#shadow-box1").removeClass("div_flex");
        $("#shadow-box1").addClass("div_none");
    }
    function openAlert1() {
        $("#shangjia11").val(0);
        $("#shadow-box1").removeClass("div_none");
        $("#shadow-box1").addClass("div_flex");
    }
    function changeSj11() {
        let check_sj_id = $("#shangjia11").val();
        if (check_sj_id!=0){
            $("#sub_upload2").show();
            $("#form_shangjiaid").val(check_sj_id);
        }else{
            $("#sub_upload2").hide();
        }
    }
    
    
    <!--    弹出表单-->
    function closeAlert() {
        $("#ad_id").val = '';
        $("#shadow-box").removeClass("div_flex");
        $("#shadow-box").addClass("div_none");
    }
    function openAlert(e) {
        let id = e.dataset.id;
        let shangjiaid = e.dataset.shangjiaid;
        let uid = e.dataset.uid;
        $("#course_id").val(id);
        $("#uid").val(uid);
        $("#shadow-box").removeClass("div_none");
        $("#shadow-box").addClass("div_flex");
    }
    //切换商家
    let sjc = [];
    function changeSj() {
        sjc = [];
        $('#course').val('');
        $('#course').html(`<option value="" >请选择课程</option>`)
        $('#adress').val('')
        $('#adress').html(`<option value="" >请选择地址</option>`)
        var nSel = document.getElementById("shangjia");
        var index = nSel.selectedIndex; // 选中索引
        var shangjiaid= nSel.options[index].value;
        let id = $("#course_id").val();
        let uid = $("#uid").val();
        let postUrl = "{php echo createWebUrl('web',array('themeid'=>$themeid,'r'=>'education.flag.editCourse'));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:{shangjia_id:shangjiaid,course_id:id,uid:uid},
            success:function (e) {
                let status = e.status;
                let result = e.result;
                console.log(e)
                sjc = e.result.data;
                const str = sjc.map(item => {
                    return `<option value="${item.id}" >${item.name}</option>`
                }).join('');
                $('#course').append(str)
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    function changeKc() {
        $('#adress').val('')
        $('#adress').html(`<option value="" >请选择地址</option>`)
        var nSel = document.getElementById("course");
        var index = nSel.selectedIndex; // 选中索引
        var course= nSel.options[index].value;
        if(sjc.length > 0) {
            const str = sjc.filter(item => item.id == course)[0].address.map(citem => `<option value="${citem}" >${citem}</option>`).join('')
            $('#adress').append(str)
        }
    }
    //修改奖品 提交数据
    function addOrEditItem() {
        var list_total = "{php echo $total;}";
        let postUrl = "{php echo createWebUrl('web',array('themeid'=>$themeid,'r'=>'education.flag.sureEditCourse'));}";
        let success_redirect = "{php echo createWebUrl('web',array('themeid'=>$themeid,'r'=>'education.flag.course'));}";
        let shangjia = $("#shangjia").val();
        let course = $("#course").val();
        let adress = $("#adress").val();
        if (!shangjia){
            layer.msg('请选择商家');
            return
        }
        if (!course){
            layer.msg('请选择课程');
            return
        }
        if (!adress){
            layer.msg('请选择地址');
            return
        }
        let formData = $("#form").serialize();
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:formData,
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.msg)
                }else{
                    layer.msg(result.msg);
                    window.location.href = success_redirect;
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
</script>
